<template>
  <div id="app">
    <!-- 路由占位符 -->
    <router-view></router-view>
  </div>
</template>

<script>
import { mapActions } from "vuex";
export default {
  name: "app",
  data() {
    return {};
  },
  created() {
    this.getProcessList();
    this.getSupplyInfo(); //获取商家投入品信息
    this.getBaseInfo(); //获取基地信息
    this.removeloadingdiv();
    this.getAllPermissionInfo(); //获取所有权限
    this.getRoleInfo();   //获取基地角色信息
    this.getAllStaffInfo()   //获取企业员工信息
    this.getSuppliersList(); //获取所有的商家名字和ID
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("store")) {
      console.log(JSON.parse(sessionStorage.getItem("store")));
      //用合并的对象替换store的state
      this.$store.replaceState(
        //将当前state里的数据放到合并到一个空对象
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(sessionStorage.getItem("store"))
        )
      );
    }
    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload", () => {
      console.log('页面刷新');
      sessionStorage.setItem("store", JSON.stringify(this.$store.state));
    });

    this.removeloadingdiv();
  },
  methods: {
    ...mapActions("process", ["getProcessList", "getStaffList"]),
    ...mapActions("roleInfo", ["getRoleInfo", "getAllPermissionInfo","getAllStaffInfo"]),
    ...mapActions("productionInfo", [
      "getSupplyInfo",
      "getBaseInfo",
      "getSuppliersList",
    ]),
    removeloadingdiv() {
        setTimeout(() => {
          let loading = document.getElementById("loading");
          if (loading !== null) {
            document.body.removeChild(loading);
          }
        },5)
    },
  },
};
</script>
<style>
#app {
  height: 100vh;
}
</style>